package com.ruangong.GitClient.GitHubAPI;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.ruangong.GitClient.R;

import java.util.List;

import android.widget.ArrayAdapter;
import android.widget.TextView;

public class GitHubFileAdapter extends ArrayAdapter<GitHubFile> {

    private List<GitHubFile> fileList;
    private LayoutInflater inflater;

    public GitHubFileAdapter(Context context, List<GitHubFile> fileList) {
        super(context, 0, fileList);
        this.fileList = fileList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = inflater.inflate(R.layout.list_item_gitfile, parent, false); // 使用自定义的布局文件
        }

        GitHubFile file = fileList.get(position);
        TextView textView = view.findViewById(R.id.text);
        ImageView imageView = view.findViewById(R.id.icon1);

        textView.setText(file.getName());
        if (file.getType().equals("dir")) {
            imageView.setImageResource(R.drawable.folder_icon); // 文件夹图标资源ID
        } else {
            imageView.setImageResource(R.drawable.file_icon); // 文件图标资源ID
        }

        return view;
    }
}

